package com.xayy.core.antlr4.exception;

import cn.kawins.base.result.CheckResult;
import cn.kawins.base.result.ResultBody;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Nie
 * @version V1.0
 * @date 2023/10/8 16:26
 */
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(CheckSyntaxException.class)
    @ResponseBody
    public ResultBody checkSyntaxException(CheckSyntaxException e) {
        return CheckResult.fail(e.getMessage()).body();
    }

    @ExceptionHandler(TelemetryNullException.class)
    @ResponseBody
    public ResultBody telemetryNullException(TelemetryNullException e) {
        return CheckResult.fail(e.getMessage()).body();
    }

    @ExceptionHandler(UndefinedInternalParamException.class)
    @ResponseBody
    public ResultBody undefinedInternalParamException(UndefinedInternalParamException e) {
        return CheckResult.fail(e.getMessage()).body();
    }

    @ExceptionHandler(UndefinedOutParamException.class)
    @ResponseBody
    public ResultBody undefinedOutParamException(UndefinedOutParamException e) {
        return CheckResult.fail(e.getMessage()).body();
    }

    @ExceptionHandler(UnexpectedResultException.class)
    @ResponseBody
    public ResultBody unexpectedResultException(UnexpectedResultException e) {
        return CheckResult.fail(e.getMessage()).body();
    }

    @ExceptionHandler(ExpressException.class)
    @ResponseBody
    public ResultBody expressException(ExpressException e) {
        return CheckResult.fail(e.getMessage()).body();
    }

    @ExceptionHandler(UnexpectedParamTypeException.class)
    @ResponseBody
    public ResultBody unexpectedParamTypeException(UnexpectedParamTypeException e) {
        return CheckResult.fail(e.getMessage()).body();
    }




}
